//       https://ac.nowcoder.com/acm/contest/11211/E





#include <iostream>
using namespace std;

int a[1010][1010];
int n, q, x, revolve, mirroring;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    cin >> q;
    while (q--)
    {
        cin >> x;
        if (x == 1)
            revolve++;
        else
            mirroring++;
    }
    if (mirroring % 2)
    {
        for (int i = 1; i <= (n / 2); i++)
            for (int j = 1; j <= n; j++)
                swap(a[i][j], a[n - i + 1][j]);
    }
    if (revolve % 2)
    {
        for (int i = n; i >= 1; i--)
        {
            for (int j = n; j >= 1; j--)
                cout << a[i][j] << " ";
            cout << endl;
        }
    }
    else
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
                cout << a[i][j] << " ";
            cout << endl;
        }
    }
    return 0;
}